package com.groupbuying.sysconfig.controller.wechat;


import com.groupbuying.sysconfig.service.wechat.WechatService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


@RestController
@RequestMapping("/Wechat")
public class WechatController {

    @Autowired
    private WechatService wechatService;



   /**
    * @api {get} /Wechat/weChatMiniApp/getOpenidAndSessionKeyByCode 通过code获取小程序的openID和sessionKey
    * @apiExample
    * author mayunfei
    * tar 用于: api内部调用
    * date 2019/10/31
    * @apiGroup sysconfig
    * @apiVersion 1.0.0
    * @apiHeader {String} Authorization 用户授权token
    * @apiParam {String} code:微信code
    * @apiParam {String} indicate:标识
    * @apiSuccess {Map} Openid
    * @apiSuccess {Map} SessionKey
    */
    @GetMapping("/weChatMiniApp/getOpenidAndSessionKeyByCode")
    public Map<String, String> getOpenidAndSessionKeyByCode(@RequestParam("code")String code,@RequestParam("indicate")String indicate) {
        return wechatService.getOpenidAndSessionKeyByCode(code);
    }


    /**
     * @api {get} /Wechat/weChatPublicApp/getMPOpenidByCode 根据前端传入code获取对应微信公众号openId及sessionKey
     * @apiExample
     * author mayunfei
     * tar 用于:api内部调用
     * date 2019/10/31
     * @apiGroup sysconfig
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} code:微信code
     * @apiParam {String} indicate:标识
     * @apiSuccess {Map} Openid
     * @apiSuccess {Map} sessionKey
     */
    @GetMapping("/weChatPublicApp/getMPOpenidByCode")
    public Map<String, Object> getMPOpenidByCode (@RequestParam("code")String code,@RequestParam("indicate")String indicate){
        return wechatService.getWechatPublicOpenidByCode(code);
    }

    /**
     * @api  {get} /Wechat/weChatPublicApp/getAccessToken 公众号accessToken
     * @apiExample
     * author mayunfei
     * tar 用于: api内部调用
     * date 2019/10/31
     * @apiGroup sysconfig
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} indicate:标识
     * @apiSuccess {String} AccessToken
     */
    @GetMapping("/weChatPublicApp/getAccessToken")
    public String getAccessToken(@RequestParam("indicate")String indicate){
        return wechatService.getAccessToken();
    }

   /**
    * @api {get}  /Wechat/weChatMiniApp/getProgramAccessToken 原生微信异步通知处理接口
    * @apiExample
    * author mayunfei
    * tar 用于:api内部调用
    * date 2019/10/31
    * @apiGroup sysconfig
    * @apiVersion 1.0.0
    * @apiHeader {String} Authorization 用户授权token
    * @apiParam {String} indicate:标识
    * @apiSuccess {String}AccessToken
    */
    @GetMapping("/weChatMiniApp/getProgramAccessToken")
    public  String getProgramAccessToken(@RequestParam("indicate")String indicate){
        return wechatService.getProgramAccessToken();
    }

    /**
     * @api {get} /Wechat/weChatMiniApp/decryptData 解密微信
     * @apiExample
     * author mayunfei
     * tar 用于:api内部调用
     * date 2019/10/31
     * @apiGroup sysconfig
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} encryptedData:解密信息
     * @apiParam {String} iv:偏移量
     * @apiParam {String} 微信:code
     * @apiParam {String} indicate:标识
     * @apiSuccess {Map} openid
     */
    @GetMapping("/weChatMiniApp/decryptData")
    public Map<String,String> decryptData(@RequestParam("encryptedData")String encryptedData, @RequestParam("iv") String iv, @RequestParam("code") String code, @RequestParam("indicate") String indicate){
        return wechatService.decryptData(encryptedData,iv,code);
    }

    /**
     * @api  {get} /Wechat/weChatPublicApp/redisAccessTokenRedisExpired 缓存失效
     * @apiExample
     * author mayunfei
     * tar 用于:api内部调用
     * date 2019/10/31
     * @apiGroup sysconfig
     * @apiVersion 1.0.0
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} null
     * @apiSuccess {String} AccessToken
     */
    @GetMapping("/weChatPublicApp/redisAccessTokenRedisExpired")
    public String redisAccessTokenRedisExpired(){
        return wechatService.redisAccessTokenRedisExpired();
    }

//    /**
//     * @api  {get} /weChatMiniApp/Decrypt 解密
//     * @apiExample
//     * author mayunfei
//     * tar 用于:api内部调用
//     * date 2019/10/31
//     * @apiGroup sysconfig
//     * @apiVersion 1.0.0
//     * @apiHeader {String} Authorization 用户授权token
//     * @apiParam {String} null
//     * @apiSuccess {String} AccessToken
//     */
//    @GetMapping("/weChatMiniApp/Decrypt")
//    public Map Decrypt(@RequestParam Map<String, Object> params) {
//        return wechatService.decrypt(params);
//    }

}
